home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UFailure.a < prev    next >
Encoding:
Text File  |  1991-05-01  |  4.6 KB  |  160 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; Failure Handler Assembly Routines
  3. ;
  4. ; KNOWN LIMITATIONS
  5. ;
  6. ; Copyright © 1984-1990 Apple Computer, Inc.  All rights reserved.
  7. ;
  8. ; when       who    what
  9. ; -------- ---- --------------------------------------------------------------
  10. ; 88.07.28 srf    add header and includes for Macros
  11. ; ----------------------------------------------------------------------------
  12.  
  13.                 Blanks        On
  14.                 String        AsIs
  15.                 Case        On
  16.  
  17.                 Print        Off
  18.                 Include     'Macros.a'
  19.  
  20.                 LOAD            'ProgStrucMacs.d'
  21.                 LOAD            'FlowCtlMacs.d'
  22.                 Print        On
  23.  
  24. ;---------------------------------------------------------------------------------------------------
  25.             
  26. nSavedRegs        Equ         12
  27.  
  28. ; flags to indicate which type of handler is stored in the FailInfo record
  29. kPascalProcCall    Equ            0
  30. kCFuncCall        Equ            1
  31.  
  32.                 Seg         'MAFailureRes'
  33. ;-------------------------------------------------------------------
  34. ;PROCEDURE CatchFailures(VAR fi: FailInfo; PROCEDURE Handler(e: INTEGER; m: LONGINT)); EXTERNAL;
  35. ;-------------------------------------------------------------------
  36. CATCHFAILURES    Proc        Export
  37.                 DATA
  38.                 Import        gTopHandler:Data
  39.                 CODE
  40.  
  41. A6Link            Equ         4                        ; static link which the Pascal compiler
  42.                                                     ; automatically pushes on the stack after
  43.                                                     ; pushing a ProcPtr ("PROCEDURE Handler")
  44. handler         Equ         A6Link + 4                ; the ProcPtr ("PROCEDURE Handler")
  45. fiVAR            Equ         handler + 4
  46. parmSize        Equ         fiVAR + 4 - A6Link
  47.  
  48.                 Head
  49.                 Move.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  50.         
  51.                 MoveM.L     A2-A7/D2-D7,(A0)        ; save All regs first
  52.                 Add         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  53.                 
  54.                 Move.W        #kPascalProcCall,(A0)+    ; set flags field.  0 is for CatchFailures 
  55.         
  56.                 Clr.W        (A0)+                    ; clear error field
  57.                 Clr.L        (A0)+                    ; clear message field
  58.         
  59.                 Lea         A6Link(SP),A1            ; save the A6Link And Proc ptr
  60.                 Move.L        (A1)+,(A0)+             ; save the A6Link
  61.                 Move.L        (A1)+,(A0)+             ; save the Proc ptr
  62.         
  63.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  64.                 Move.L        fiVAR(SP),gTopHandler(A5)
  65.     If    qDebug Then
  66.                 Move.L        (SP),(A0)+                ; remember the caller's PC
  67.     EndIf
  68.  
  69. exit
  70.                 Move.L        (SP)+,A0
  71.                 Add.L        #parmSize,SP
  72.                 Jmp         (A0)
  73.                 Tail        CATCHFAILURES
  74.         
  75. ;-------------------------------------------------------------------
  76. ;FUNCTION Try(VAR fi: FailInfo): BOOLEAN; EXTERNAL C;
  77. ;-------------------------------------------------------------------
  78. Try                Proc        Export
  79.                 DATA
  80.                 Import        gTopHandler:Data
  81.                 CODE
  82.  
  83. fiVAR            Equ          4
  84. parmSize        Equ         fiVAR
  85.  
  86.                 Head
  87.                 Move.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  88.         
  89.                 MoveM.L     A2-A7/D2-D7,(A0)        ; save All regs first
  90.                 Add         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  91.                 
  92.                 Move.W        #kCFuncCall,(A0)+        ; set flags field.  1 is for Try 
  93.         
  94.                 Clr.W        (A0)+                    ; clear error field
  95.                 Clr.L        (A0)+                    ; clear message field
  96.         
  97.                 Clr.L        (A0)+                     ; clear the A6Link.  Not used with Try
  98.                 Move.L        (SP), (A0)+             ; save the return address as the continuation ptr
  99.         
  100.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  101.                 Move.L        fiVAR(SP),gTopHandler(A5)
  102.     If    qDebug Then
  103.                 Move.L        (SP),(A0)+                ; remember the caller's PC
  104.     EndIf
  105.  
  106. exit
  107.                 Move.L        (SP)+,A0
  108. ;                Add.L        #parmSize,SP
  109.                 Move.W        #1,D0                    ; Boolean true, enter the conditioned block of code to try
  110.                 Jmp         (A0)
  111.                 Tail        Try
  112.         
  113.  
  114.                 Seg         'MAFailureRes'
  115. ;-------------------------------------------------------------------
  116. ;PROCEDURE DoFailure(pf: PFailInfo); EXTERNAL;
  117. ;-------------------------------------------------------------------
  118. DOFAILURE        Proc        Export
  119.                 Import        FAILURE
  120.  
  121. pf                Equ         4
  122.  
  123.                 Head
  124.                 Move.L        pf(SP),A0                ; get pointer to FailInfo
  125.                 MoveM.L     (A0),A2-A7/D2-D7        ; restore regs (can't use A7 anymore)
  126.                 Add         #nSavedRegs*4,A0        ; advance pointer
  127.         
  128.                 CmpI.W        #kPascalProcCall,(A0)+
  129.                 Beq.S        PascalProcCall
  130.                 Clr.W        D0                        ; Boolean false, enter the conditioned block of failure code
  131.                 Move.l        10(A0),A0
  132.                 Jmp            (A0)
  133.  
  134. PascalProcCall
  135.                 Move.W        (A0)+,D0                ; get error
  136.                 Move.L        (A0)+,D1                ; And message
  137.  
  138.                 MoveM.L     D0/D1,-(SP)             ; save for later use
  139.         
  140.                 Move.W        D0,-(SP)
  141.                 Move.L        D1,-(SP)                ; parameters to failure handler
  142.                 
  143.                 Move.L        (A0)+,D0                ; check the A6Link
  144.                 Beq.S        @1                        ; If NIL Then don't pass it
  145.                 Move.L        D0,-(SP)                ; Else Do pass it
  146. @1
  147.                 Move.L        (A0)+,A0                ; get address of failure handler
  148.         
  149.                 Jsr         (A0)                    ; call failure handler
  150.  
  151.                 MoveM.L     (SP)+,D0/D1             ; get error & message back
  152.                 Move.W        D0,-(SP)
  153.                 Move.L        D1,-(SP)                ; parameters to Failure
  154.                 Jsr         FAILURE
  155.                 
  156.                 ; should Not return
  157.                 Tail    DOFAILURE
  158.         
  159.                 End
  160.